package com.huazai.juc.core;

public class TraditionalProducerConsumer {
    public static void main(String[] args) {
        ShareData shareData = new ShareData();
        // producer线程，负责生产
        new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                try {
                    shareData.increment();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, "producer").start();

        // consumer线程，负责消费
        new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                try {
                    shareData.decrement();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, "consumer").start();
    }
}
